package com.wangzhenyu.learn.test.designPattern


//适配器模式


//被适配的类
open class Voltage220 {

    fun output220(): Int {
        val src = 220
        println("电压： $src 伏")
        return src
    }

}

//适配类的接口
interface Voltage5 {
    fun output5(): Int
}


//类适配器
class VoltageAdapter01 : Voltage220(), Voltage5 {

    override fun output5(): Int {
        var src = output220()
        src /= 44
        println("电压： $src 伏")
        return src
    }

}

//对象适配器
class VoltageAdapter02(private val voltage: Voltage220) : Voltage5 {

    override fun output5(): Int {
        var src = voltage.output220()
        src /= 44
        println("电压： $src 伏")
        return src
    }
}

class Phone {

    fun charging(voltage: Voltage5) {
        val temp = if (voltage.output5() == 5) "正在充电" else "无法充电"
        print(temp)
    }
}